<html>
	<head>
		<% content_for :title, t("borrowBook") %>
	</head>
	<body>
	<div class="feat_prod_box_details">
	<div class="contact_form1">
		<div class="form_subtitle">
				<%= t("listRequest")%>
			</div>

<table class="table">
	<tr class="book_manager">
		<th class="table" width="10%"><%= t("userRequest")%></th>
		<th class="table" width="40%"><%= t("book")%></th>
		<th class="table" width="40%"><%= t("Requesttime")%></th>
		<th class="table" width="10%"></th>
	</tr>
<div class="book_color">
	<% i=0%>
	<% @requests.each do |request| %>
	<% abook = @books[i]%>
	<% aUser = @users[i]%>
	<% i+=1 %>
	<tr class="table">
		<td class="table"> <%= aUser.username %></td>
		<td class="table"><%= abook.title %></td>
		<td class="table" style="text-align: center"><%= request.request_time %></td>

		<% if session[:user].role == 'admin'%>
		<td class="table" style="text-align: center"><a href="" onclick="return Check(<%= abook.quantity%>)"><%= t("check")%></a><br />
			<a href="requests/accept" onclick="location.href=this.href+'?id='+ <%= request.id%>
		;return false;"><%= t("Accept")%></a><br
		 /><%= link_to t("Ignore"), request, method: :delete, data: { confirm: t("areyousure") } %></td>
		<% else %>
		<td class="table" style="text-align: center">  <%= link_to t("Cancel"), request, method: :delete, data: { confirm: t("areyousure") }%> </td>
		<% end%>
	</tr>
	<% end %>
	</div>

	<script type = "text/javascript">
		function Check(id) {
			if (id > 1) {
				alert("<%= t("canborrow")%>");
			} else {
				alert("<%= t("cannotborrow")%>");
			}
		}

	</script>
</table>
</div>
</div>
<br />

<!-- Listing all Borrow Book-->
<div class="feat_prod_box_details">
	<div class="contact_form1">
		<div class="form_subtitle">
			<%= t("listborrow")%>
			</div>
<table class="table">
	<tr class="table">
		<th class="table" width="10%"><%= t("userRequest")%></th>
		<th class="table" width="40%"><%= t("book")%></th>
		<th class="table" width="20%"><%= t("borrowdate")%></th>
		<th class="table" width="20%"><%= t("deadlinedate")%></th>
		<%if session[:user].role == "admin"%>
		<th class="table" width="10%"></th>
		<%end%>
	</tr>
	<% i=0%>
	<% @borrow_books.each do |borrow_book| %>
	<% abook = @books1[i]%>
	<% aUser = @users1[i]%>
	<% i+=1 %>
	<tr class="table">
		<% if (borrow_book.return_date == nil)%>
		<td class="table"><%= aUser.username %></td>
		<td class="table"><%= abook.title %></td>
		<td class="table" style="text-align: center"><%= borrow_book.borrow_date %></td>
		<td class="table" style="text-align: center"><%= borrow_book.deadline_date %></td>
		<% if session[:user].role == "admin"%>
		<td class="table" style="text-align: center">
			<a href="requests/returnBook" onclick="location.href=this.href+'?bid='+ <%= borrow_book.id%>
		;return false;"><%= t("return")%></a></td>
		<% end %>
		<% end %>
	</tr>
	<% end %>
</table>
</div>
</div>
<br />

<!-- Listing all Borrow Book-->
<div class="feat_prod_box_details">
	<div class="contact_form1">
		<div class="form_subtitle">
			<%= t("listreturn")%>
			</div>
<table class="table">
	<tr class="table">
		<th class="table" width="10%"><%= t("userRequest")%></th>
		<th class="table" width="45%"><%= t("book")%></th>
		<th class="table" width="15%"><%= t("borrowdate")%></th>
		<th class="table" width="15%"><%= t("deadlinedate")%></th>
		<th class="table" width="15%"><%= t("returndate")%></th>
	</tr>

	<% i=0%>
	<% @borrow_books.each do |borrow_book| %>
	<% abook = @books1[i]%>
	<% aUser = @users1[i]%>
	<% i+=1 %>
	<tr>
		<% if (borrow_book.return_date != nil)%>
		<td class="table"><%= aUser.username %></td>
		<td class="table"><%= abook.title %></td>
		<td class="table" style="text-align: center"><%= borrow_book.borrow_date %></td>
		<td class="table" style="text-align: center"><%= borrow_book.deadline_date %></td>
		<td class="table" style="text-align: center"><%= borrow_book.return_date %></td>
		<% end%>
	</tr>
	<% end %>
</table>
</div>
</div>

<br />
</body>
</html>

